package com.halko.PR.pr.chars;

import java.util.Vector;

import org.bytedeco.javacpp.opencv_core.Mat;

/**
 * 字符识别与分割
 * @author halko
 * @create 2021-04-07 11:58
 */
public class CharsRecognition {

    private CharsSegment charsSegment = new CharsSegment();
    private CharsIdentify charsIdentify = new CharsIdentify();

    /**
     * 是否开启调试模式
     *
     * @param isDebug
     */
    public void setCRDebug(final boolean isDebug) {
        charsSegment.setDebug(isDebug);
    }

    /**
     * 获取调试模式状态
     *
     * @return
     */
    public boolean getCRDebug() {
        return charsSegment.getDebug();
    }

    public String charsRecognition(Mat plate) {
        // 车牌字符方块集合
        Vector<Mat> matVec = new Vector<Mat>();
        // 车牌识别的字符
        String plateIdentify = "";

        int result = charsSegment.charsSegment(plate, matVec);
        if (result == 0) {
            for (int j = 0; j < matVec.size(); j++) {
                Mat charMat = matVec.get(j);
                // 默认首个字符块是中文字符
                String charcater = charsIdentify.charsIdentify(charMat, (0 == j), (1 == j));
                plateIdentify = plateIdentify + charcater;
            }
        }
        return plateIdentify;
    }
}
